from django.shortcuts import render
from django.http import HttpResponse
from django.http import HttpResponseRedirect
import logging

# Create your views here.

log = logging.getLogger("log_file")


def index(request):
    print(f"username is {request.session.get('username')}")
    print(f"password is {request.session.get('password')}")

    log.info("这是一条日志")
    log.error("报警了啊")

    print("#####################################")
    print(request)
    print("#####################################")
    if request.method == 'GET':
        print("hello world")
        return HttpResponse("hello get")
    elif request.method == 'POST':
        print("hello post")
        return HttpResponse("hello post")


def login(request, name, age):

    request.session["username"] = "malphite"
    request.session["password"] = "12345678"

    print(f"name is {name}")
    print(f"age is {age}")
    print("welcome to login page")
    context = {}
    return render(request, "login/login.html", context)


def login1(request):
    print("welcome to login page")
    return HttpResponse("login ..................")


def to_page(request):
    print("toPage.................")


def to_baidu(request):
    return HttpResponseRedirect("https://www.baidu.com")
